Replace big JS dict with JSON parsing - #71250
Conversation
|
Nice! This is huge for embedded crates! |
d61dd67 to
b4fb306
Compare
|
It would be nice if this could include a statement of the schema of the index, that way |
|
It's the same as before. But if you the schema anyway, I can send it to you? |
|
Having it formally stated would be good. Parsing JSON in rustup is plausible, where running arbitrary javascript was not :D |
commented
Apr 17, 2020
|
Cool!However, is possible to minify the Json search index to reduce the file size? |
|
No. That's something I've been working on for a long time and I was able to get some improvements, but nothing extraordinary. The best we can do for the moment is compressing the result (which I expect is done by the users wanting to host their own doc). |
commented
Apr 18, 2020
|
Google Chrome team gives an awesome video to explain why the |
left a comment
There was a problem hiding this comment.
I'm sad that we're not adding a searchIndex.json file and then loading that in searchIndex.js but I can understand the goal of simplicity.
Would it be possible to have the JSON as a separate file?
Also, doesn't the compiler have serde these days? If so, should we consider filing a help-wanted to convert this into serde code to make it less string-faffy in the future (not for this PR) ?
commented
Apr 18, 2020
|
I'm content with it as-is, though I'd prefer to see the JSON as a separate file if that's not a huge amount of work. @GuillaumeGomez Have a ponder over my points in the review, and if you feel things are OK enough as-is, or that splitting the JSON into a separate file is too hard for now, then you have r=me. |
commented
Apr 18, 2020
|
@kinnison As I know, if we use search-index.json, then we need an extra step to load the JSON file via HTTP request, which brings no efficient, even worse than the current implementation. |
commented
Apr 18, 2020
|
That load could be deliberately done as an asynchronous operation, enabling the search box only when the load is complete, and that means the actual usable page load could be faster; but as I said, I'm happy if that doesn't happen in this PR. |
|
This is what I tried at first, but you can't load a JSON file locally because of security concerns, meaning that we'd need an HTTP server when using local docs, which I'm strongly opposed to. So unfortunately, we're still forced to keep the JSON as a string in the same file... Also, the problem here isn't the download of the file but the JS parsing (which is now kinda solved since there is almost no JS). |
commented
Apr 20, 2020
|
📌 Commit b4fb306 has been approved by |
commented
Apr 20, 2020
|
💡 This pull request was already approved, no need to approve it again.
|
commented
Apr 20, 2020
|
📌 Commit b4fb306 has been approved by |
commented
Apr 20, 2020
|
⌛ Testing commit b4fb306 with merge aeeae8925dcc1f8a1bb0062efd5d9ba61afd856a... |
commented
Apr 20, 2020
|
@bors retry (included in rollup) |
commented
Apr 20, 2020
|
☔ The latest upstream changes (presumably #71356) made this pull request unmergeable. Please resolve the merge conflicts. |
This comment has been minimized.
This comment has been minimized.
|
@alecmocatta JSONP isn't really a solution, as it brings the problem we are trying to avoid in the first place - embedding data in script context. Still, the search isn't immediately required on load (user likely won't interact with it withing first second anyway), so time to first paint could still be improved by not waiting on it. Possible solution might involve |
commented
Jun 12, 2020
|
@Frizi Sorry, I was misinterpreting a comment upthread. I was meaning storing the search index as a file like: callback(JSON.parse("{...}"))which it turns out is exactly what this PR is doing! |
commented
Jun 19, 2020
|
@Frizi If you load a page with search query in the URL, search will kick in pretty early (but I'm nitpicking here :p). @alecmocatta: Yes absolutely. Glad to see we're on the same page! |
Part of #56545.
@ollie27 suggested that using JSON instead of a JS dict might be faster, so I decided to test it. And the results far exceeded whatever expectations I had...
I used https://github.com/adamgreig/stm32ral for my tests. If you want to build it locally:
But I strongly recommend to do it with this PR. Some numbers:
I think the results are clear enough...
r? @ollie27
cc @rust-lang/rustdoc